function TrManager(app, tableDiv, formDiv, filterDiv) {

	var self = this;
	this.bookId = null;
	this.view = new TrTableView(this, tableDiv, app.accountManager, app.currencyManager, app.categoryManager, null, {});
	this.trView = new TrView(this, formDiv);
	$(this.view).on('tr-selected', function(event, data) {
		if(data.item) {
			self.trView.setTransaction(data.item);
		}
	});
	$(this.trView).on('tr-reset', function() {
		self.view.cleanSelection();
	});

	this.filter = new TrFilter(true);
	this.filterView = new TrFilterView(this, filterDiv, this.filter);
	this.transactions = new Array();
	this.page = strToInt($.jqx.cookie.cookie("trPage"), 1);
	this.pageSize = strToInt($.jqx.cookie.cookie("trPageSize"), 2);
	this.xhr = null;
	$.subscribe(this.view.pagerDiv + '-page-changed', function(event, data) {
		self.gotoPage(data.page);
	});
	$.subscribe(this.view.pagerDiv + '-pageSize-changed', function(event, data) {
		self.setPageSize(data.pageSize);
	});
	$(this.view).on('sort-change', function(event, data) {
		self.loadTransactions(this.bookId, data.sorting);
	});

	this.loadTransactions = function(bookId, sorting) {
		if(bookId !== undefined) {
			this.bookId = bookId;
		}
		var trSorting;
		if(sorting !== undefined) {
			trSorting = sorting;
		} else {
			trSorting = new Sorting('date', SortDir.ASC);
		}

		app.showProgress('Загрузка транзакций ...');
		if(this.xhr != null) {
			this.xhr.abort();
			this.xhr = null;
		}
		this.xhr = $.ajax({
			url: 'service/transactions/read.txt',
			type: 'POST',
			data: { bookId: this.bookId, page: this.page, pageSize: this.pageSize, filter: this.filter.getValue(), sorting: trSorting.getValue() },
			async: true,
			cache: false,
			success: function (data, status, xhr) {
				self.xhr = null;
				self.transactions.length = 0;
				var response = $.parseJSON(data);
				$.each(response.items, function(index, transaction) {
					self.transactions.push(new Transaction().fromJson(transaction));
				});

				self.view.update(self.transactions, response.total, self.page, self.pageSize, new Sorting(response.sorting.field, response.sorting.dir));
				app.showNotification('Транзакции загружены', 1000);
			},
			error: function () {
				self.xhr = null;
				app.showWarning('Не удалось загрузить транзакции', 5000);
			}
		});
	};

	this.onFilterChanged = function(filter) {
		this.loadTransactions(this.bookId, filter);
	};

	this.gotoPage = function(page) {
		var load = (this.page !== page);
		this.page = page;
		$.jqx.cookie.cookie("trPage", page);
		if(load) {
			this.loadTransactions(this.bookId);
		}
	};

	this.setPageSize = function(pageSize) {
		var load = (this.pageSize !== pageSize);
		this.pageSize = pageSize;
		$.jqx.cookie.cookie("trPageSize", pageSize);
		if(load) {
			this.page = 1;
			$.jqx.cookie.cookie("trPage", this.page);
			this.loadTransactions(this.bookId);
		}
	};

	this.removeTransaction = function(trId) {
		console.log('to remove transaction ' + trId);
	};
};